//
//  DepreTableViewCell.m
//  CarHome
//
//  Created by 张世琦 on 14-9-18.
//  Copyright (c) 2014年 WJN_work@163.com. All rights reserved.
//

#import "DepreTableViewCell.h"
#import "DepreModel.h"
#import "DepreCarModel.h"
#import "UIImageView+WebCache.h"

@implementation DepreTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self createCarImageView];
        [self createCityLabel];
        [self createDepreLabel];
        [self createImageView];
        [self createNameLabel];
        [self createPriceLabel];
        [self createSellLabel];
        [self createShopLabel];
        [self createLabel];
    }
    return self;
}

//自定义cell图片
- (void)createImageView
{
    _car_image = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 100, 60)];
    [self.contentView addSubview:_car_image];
    [_car_image release];
}

//车名
- (void)createNameLabel
{
    _name_label = [[UILabel alloc] initWithFrame:CGRectMake(120, 10, 200, 40)];
    _name_label.numberOfLines = 2;
    [_name_label setFont:[UIFont fontWithName:@"Arial" size:15]];
    [self.contentView addSubview:_name_label];
    [_name_label release];
}

//降价
- (void)createDepreLabel
{
    _depre_label = [[UILabel alloc] initWithFrame:CGRectMake(120, 45, 100, 25)];
    [self.contentView addSubview:_depre_label];
    [_depre_label release];
}

//价格
- (void)createPriceLabel
{
    _price_label = [[UILabel alloc] initWithFrame:CGRectMake(230, 45, 90, 25)];
    [self.contentView addSubview:_price_label];
    [_price_label release];
}

//城市
- (void)createCityLabel
{
    _city_label = [[UILabel alloc] initWithFrame:CGRectMake(10, 80, 60, 20)];
    [_city_label setFont:[UIFont fontWithName:@"Arial" size:12]];
    [self.contentView addSubview:_city_label];
    [_city_label release];
}

//店铺名
- (void)createShopLabel
{
    _shop_label = [[UILabel alloc] initWithFrame:CGRectMake(75, 80, 150, 20)];
//    NSDictionary *fontDic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Arial" size:15], NSFontAttributeName, nil];
//    CGSize size = [_shop_label.text boundingRectWithSize:CGSizeMake( 320, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:fontDic context:NULL].size;
    [_shop_label setFont:[UIFont fontWithName:@"Arial" size:12] ];
    _shop_label.textAlignment = NSTextAlignmentCenter;
    [_shop_label setNumberOfLines:0];
    [self.contentView addSubview:_shop_label];
    [_shop_label release];
}

//销售范围
- (void)createSellLabel
{
    _sell_label = [[UILabel alloc] initWithFrame:CGRectMake(225, 80, 50, 20)];
    [_sell_label setFont:[UIFont fontWithName:@"Arial" size:12] ];
    [self.contentView addSubview:_sell_label];
    [_sell_label release];
}

//货源数
- (void)createCarImageView
{
    _type_image = [[UIImageView alloc] initWithFrame:CGRectMake(275, 80, 40, 18)];
    [self.contentView addSubview:_type_image];
    [_type_image release];
}

- (void)createLabel
{
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 98, 320, 10)];
    label.backgroundColor = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:0.5];
    [self.contentView addSubview:label];
    [label release];
}

#pragma mark -
#pragma mark 赋值

- (void)setCarUrl:(NSString *)carUrl name:(NSString *)name type:(NSString *)type depre:(CGFloat)depre price:(CGFloat)price  city:(NSString *)city shop:(NSString *)shop sell:(NSString *)sell typeUrl:(NSString *)typeUrl
{
    [_car_image sd_setImageWithURL:[NSURL URLWithString:carUrl] placeholderImage:[UIImage imageNamed:@"nopicture.jpg"]];
    [_name_label setText:[NSString stringWithFormat:@"%@  %@", name, type]];
    [_depre_label setText:[NSString stringWithFormat:@"%@%.2f%@",@"降", depre - price, @"万"]];
    [_price_label setText:[NSString stringWithFormat:@"%.2f%@", price, @"万"]];
    [_city_label setText:city];
    [_shop_label setText:shop];
    [_sell_label setText:sell];
    [_type_image sd_setImageWithURL:[NSURL URLWithString:typeUrl]];
}

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
